// https://leetcode.cn/problems/available-captures-for-rook/
// Created by ade on 2022/10/12.
//
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int numRookCaptures(vector <vector<char>> &board) {
        vector <vector<int>> directions = {{-1, 0},
                                           {1,  0},
                                           {0,  1},
                                           {0,  -1}};
        vector<int> r = findR(board);
        int count = 0;
        for (auto &d : directions) {
            int i = r[0] + d[0];
            int j = r[1] + d[1];
            while (i >= 0 && i < 8 && j >= 0 && j < 8) {
                if (board[i][j] == 'B') break;
                if (board[i][j] == 'p') {
                    count++;
                    break;
                }
                i += d[0];
                j += d[1];
            }
        }
        return count;

    }

    vector<int> findR(vector <vector<char>> &board) {
        vector<int> res(2);
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                if (board[i][j] == 'R') {
                    res[0] = i;
                    res[1] = j;
                    return res;
                }
            }
        }
        return res;
    }
};

int main() {
//    string s = "ababababababababababababcbabababababababababababa";
//    string s = "cdd";
//    Solution so;
//    int a = so.numRookCaptures(s);
//    cout << a << endl;
//    return 0;
}